/**
 * 
 */
package com.seascape.swms.framework.util;

import java.lang.reflect.Field;

/**
 * @author Lay
 *
 */
public class BeanUtil {

	public static <T> T emptyToNull(T source) {
		Field[] fields = source.getClass().getDeclaredFields();
		try {
			for (Field field : fields) {
				if (field.getGenericType().getTypeName().equals(String.class.getTypeName())) {
					field.setAccessible(true);
					Object obj = field.get(source);
					if (obj != null && obj.equals("")) {
						field.set(source, null);
					}
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return source;
	}
}
